local terminal = {}
local mode = require "librawmode"

function terminal:new(object)
	object = object or {}
	self.__index = self
	setmetatable(object, self)
	return object
end

function terminal:set_raw_mode()
	mode.enter_raw_mode()
end

function terminal:restore_normal_mode()
	mode.exit_raw_mode()
end

function terminal:get_terminal_size()
	local handle = io.popen("stty size", "r")
	if handle == nil then return nil, nil end
	local result = handle:read("a")
	handle:close()

	local cols, rows = result:match("(%d+) (%d+)")
	return tonumber(rows), tonumber(cols)
end

return terminal